﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Ext.Net;

public partial class Admins_Users : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData_Users();
        }
    }

    protected void LoadData_Users()
    {
        try
        {
            List<User> list = new List<User>();

            UserBLL userBLL = new UserBLL();
            DataTable dt = new DataTable();
            dt = userBLL.Users();

            foreach (DataRow item in dt.Rows)
            {
                User user = new User()
                {
                    UserID = Int32.Parse(item["UserID"].ToString()),
                    Username = item["Username"].ToString(),
                    Fullname = item["FullName"].ToString(),
                    Gender = item["Gender"].ToString(),
                    //DateOfBirth = DateTime.Parse(item["DateOfBirth"].ToString()),
                    Telephone = item["Telephone"].ToString(),
                    Email = item["Email"].ToString(),
                    IdentityCard = item["IdentityCard"].ToString(),
                    Address = item["Address"].ToString()
                };

                list.Add(user);
            }
            list.Sort((new SortUsers()).Compare);

            StoreUsers.DataSource = list;
            StoreUsers.DataBind();

            GridPanelUsers.ActiveIndex = -1;
        }
        catch (Exception)
        {
            X.Msg.Notify("Thông báo", "Hệ thống đang bận, hãy thử lại sau").Show();
        }
    }


    protected void StoreUsers_ReadData(object sender, Ext.Net.StoreReadDataEventArgs e)
    {
        LoadData_Users();
    }

    protected void ToolbarShowAdd_DirectClick(object sender, DirectEventArgs e)
    {
        WindowCreateUsers.Hidden = false;
    }


    [DirectMethod]
    public void Create_Users()
    {

    }
}